//
//  CJSHotTableViewCell.m
//  GoTraveling
//
//  Created by 陈金山 on 15/12/24.
//  Copyright © 2015年 开发华佗. All rights reserved.
//

#import "CJSHotTableViewCell.h"
#import "UIImageView+WebCache.h"
#import "GSYImageView.h"

@interface CJSHotTableViewCell ()

@property (nonatomic, retain) UIView *backgView;

@property (nonatomic, retain) UIImageView *headImageView;

@property (nonatomic, retain) UILabel *titleLabel;

@property (nonatomic, retain) UILabel *title;

@property (nonatomic, retain) UIImageView *userImageView;

@property (nonatomic, retain) UILabel *userName;

@end

@implementation CJSHotTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.contentView.backgroundColor = [UIColor colorWithRed:0.980 green:0.961 blue:0.910 alpha:1.000];
        [self createSubViews];
    }
    return self;
}

- (void)createSubViews {
    
    self.backgView = [[UIView alloc] initWithFrame:CGRectMake(10 * ADAPT_WIDTH, 5, SCREEN_WIDTH - (20 * ADAPT_WIDTH), 265)];
    self.backgView.layer.cornerRadius = 5;
    self.backgView.layer.masksToBounds = YES;
    [self.contentView addSubview:self.backgView];
    
    GSYImageView *occupyImage = [[GSYImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH - (20 * ADAPT_WIDTH), 150)];
    [self.backgView addSubview:occupyImage];
    
    self.headImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH - (20 * ADAPT_WIDTH), 150)];
    self.headImageView.contentMode = UIViewContentModeScaleAspectFill;
    self.headImageView.layer.masksToBounds = YES;
    [self.backgView addSubview:self.headImageView];
    
    self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 10, self.backgView.frame.size.width - 40, 35)];
    self.titleLabel.font = [UIFont systemFontOfSize:22 weight:0.8];
    self.titleLabel.numberOfLines = 1;
    self.titleLabel.shadowColor = [UIColor grayColor];
    self.titleLabel.shadowOffset = CGSizeMake(1, 1);
    self.titleLabel.textColor = [UIColor whiteColor];
    [self.backgView addSubview:self.titleLabel];
    
    self.title = [[UILabel alloc] initWithFrame:CGRectMake(10, self.headImageView.frame.size.height + 10, self.headImageView.frame.size.width - 20, 55)];
    self.title.numberOfLines = 0;
    self.title.font = [UIFont systemFontOfSize:15];
    self.title.textColor = [UIColor grayColor];
    
    [self.backgView addSubview:self.title];
    
    CGFloat height = self.title.frame.origin.y + self.title.frame.size.height;
    
    UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(10, height + 5, self.backgView.frame.size.width - 20, 1)];
    lineView.backgroundColor = [UIColor colorWithRed:0.88 green:0.87 blue:0.85 alpha:1];
    [self.backgView addSubview:lineView];
    
    self.userImageView = [[UIImageView alloc] initWithFrame:CGRectMake(20, height + 15, 25, 25)];
    self.userImageView.layer.cornerRadius = self.userImageView.frame.size.width / 2;
    self.userImageView.layer.masksToBounds = YES;
    [self.backgView addSubview:self.userImageView];
    
    self.userName = [[UILabel alloc] initWithFrame:CGRectMake(70, self.userImageView.frame.origin.y, self.contentView.frame.size.width - 20, 35)];
    self.userName.textColor = [UIColor colorWithWhite:0.671 alpha:1.000];
    self.userName.font = [UIFont systemFontOfSize:17];
    
    [self.contentView addSubview:self.userName];
}

- (void)setTypeTen:(TypeTen *)typeTen {
    _typeTen = typeTen;
    
    if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"states"] isEqualToString:@"1"]) {
        self.backgView.backgroundColor = [UIColor colorWithRed:0.18 green:0.21 blue:0.24 alpha:1];
    }
    else {
        
        self.backgView.backgroundColor = [UIColor whiteColor];
    }
    [self.headImageView sd_setImageWithURL:[NSURL URLWithString:self.typeTen.index_cover]];
    self.titleLabel.text = self.typeTen.index_title;
    self.title.text = self.typeTen.text;
    [self.userImageView sd_setImageWithURL:[NSURL URLWithString:self.typeTen.users.avatar_m] placeholderImage:[UIImage imageNamed:@"avatar_placeholder_26"]];
    self.userName.text = self.typeTen.users.name;
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
